<?php
/**
 * Created by PhpStorm.
 * Admin: Administrator
 * Date: 2018/6/6/006
 * Time: 9:32
 */

namespace App\Http\Controllers\Product;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Service\Product\ProductService;
use App\Http\Controllers\Controller;
//use Illuminate\Support\Facades\Redis;
use Session,Config;
use Cache;

class RechargeController extends Controller
{
    /**
     * @return view
     * Demo页面
     */
    public function index()
    {
        return view('Product.rechargelist');
    }

    /**
     * @param Request $request
     * 充值套餐列表
     */
    public function getRechargeList(Request $request)
    {

        $where= $request->except('_token');

        if($request->has('page'))
        {
            $where['page_no'] = $request->input('page');
            unset($where['page']);
        }
        if($request->has('limit'))
        {
            $where['page_size'] = $request->input('limit');
            unset($where['limit']);
        }else{
            $where['page_size'] = 10;
        }

        foreach($where as $key=>$value)
        {
            if($value =='' || $value == 'undefined')
            {
                unset($where[$key]);
            }
        }

        $user = new ProductService();
        $data = $user->getRechargeList($where);

        if($data && !empty($data['data']))
        {
            foreach ($data['data'] as &$v)
            {
                $v['status_name'] = $v['status'] == 1 ? '上线':'下线';
            }
        }


        return $data;

    }



    /**
     * @param Request $request
     * 添加充值套餐
     */
    public function addRecharge(Request $request)
    {

        $where = $request->except('_token');


        $user = new ProductService();

        $ret =  $user->addRecharge($where);

        if($ret)
        {
           return $ret;
        }

    }


    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     * 删除充值套餐信息
     */
    public function delRecharge(Request $request)
    {

        $where = [];
        $where['recharge_id']=trim($request->input('recharge_id'),',');


        $user = new ProductService();
        $data = $user->delRechargeProduct($where);

        if($data)
        {
            return $data;
        }

    }

    /**
     * @param Request $request
     * 修改充值套餐信息
     */
    public function updateRecharge(Request $request)
    {
        $where = [];
        $where= $request->except('_token');


        $user = new ProductService();
        $data = $user->updateRecharge($where);

        if($data)
        {
            return $data;
        }
    }






}